package com.yango.teach.controller;


import com.yango.commonutil.result.Result;
import com.yango.teach.entity.vo.subject.OneSubjectVo;
import com.yango.teach.service.SubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author LiDingYin
 * @since 2021-07-24
 */
@Api(description = "课程分类 前端控制器")
@RestController
@RequestMapping("/teach/subject")
public class SubjectController {

    @Autowired
    private SubjectService subjectService;

    //Excel导入课程分类
    @ApiOperation(value = "Excel导入课程分类")
    @PostMapping("/importSubject")
    public Result importSubject(@ApiParam(name = "file", value = "请选择文件", required = true)
                                        MultipartFile file) {
        //获取上传的文件MultipartFile
        subjectService.importSubject(file, subjectService);
        return Result.ok().message("导入课程分类成功!");
    }

    //获取分类列表（树形结构）
    @ApiOperation(value = "获取分类列表（树形结构）")
    @GetMapping("/getSubjectList")
    public Result getSubjectList() {
        List<OneSubjectVo> subjectVoList = subjectService.getSubjectList();
        return Result.ok().data("subjectVoList", subjectVoList);
    }

}

